package com.jimmy.medical.controller;

import com.jimmy.medical.entity.FlowOrder;
import com.jimmy.medical.entity.RechargeRecord;
import com.jimmy.medical.model.AjaxResult;
import com.jimmy.medical.model.UserAchieve;
import com.jimmy.medical.service.IPersonalService;
import com.jimmy.medical.util.AjaxUtils;
import com.jimmy.medical.util.Func_T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/personal")
public class PersonalController {

    @Autowired
    private IPersonalService personalService;


    /**
     * 员工业绩
     * @return
     */
    @RequestMapping("/userAchieve")
    @ResponseBody
    public AjaxResult<UserAchieve> userAchieve(final Long userId) {
        return AjaxUtils.process(new Func_T<UserAchieve>() {
            @Override
            public UserAchieve invoke() throws Exception {
                UserAchieve userAchieve = new UserAchieve();
                userAchieve.setServiceCountToday(personalService.serviceToday(userId));
                userAchieve.setSaleCountToday(personalService.saleToday(userId));
                userAchieve.setTodayMoney(personalService.moneyToday(userId));
                userAchieve.setMonthMoney(personalService.moneyMonth(userId));
                return userAchieve;
            }
        });
    }

    /**
     * 销售业绩
     * @return
     */
    @RequestMapping("/userSaleList")
    @ResponseBody
    public AjaxResult<List<RechargeRecord>> userSaleList(final Long userId) {
        return AjaxUtils.process(new Func_T<List<RechargeRecord>>() {
            @Override
            public List<RechargeRecord> invoke() throws Exception {
                List<RechargeRecord> list = personalService.getRechargeRecordList(userId);
                return list;
            }
        });
    }

    /**
     * 服务业绩
     * @return
     */
    @RequestMapping("/userServiceList")
    @ResponseBody
    public AjaxResult<List<FlowOrder>> userServiceList(final Long userId) {
        return AjaxUtils.process(new Func_T<List<FlowOrder>>() {
            @Override
            public List<FlowOrder> invoke() throws Exception {
                return personalService.getFlowOrderList(userId);
            }
        });
    }
}
